package com.catmiw.wyz;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;

public class MailTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HtmlEmail  email = new HtmlEmail ();
		email.setHostName("mail.hbxxjl.com");
		//email.setSmtpPort(25);
//		email.setAuthenticator(new DefaultAuthenticator("wl@hbxxjl.com", "t6789223"));
		//email.setTLS(true);
		try {
			email.setFrom("wl@hbxxjl.com");
			email.setSubject("TestMail2");
			// embed the image and get the content id
			URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
			String cid = email.embed(url, "Apache logo");

			// set the html message
			email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>");

			// set the alternative message
			email.setTextMsg("Your email client does not support HTML messages");

			email.addTo("13995588186@139.com");
			email.send();
		} catch (EmailException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
